var auth = {};

auth.init = function() {

};

auth.googleSingin = function() {
    var clientId = '776328974396-0a34jrougndvd68mur2b7be9kpd208g0.apps.googleusercontent.com';
    var apiKey = 'AIzaSyBsaaGa9F_Nb_LlB5zpRnjAazk5QmuPrKQ';
    var scopes = 'https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/plus.profile.emails.read';
    gapi.client.setApiKey(apiKey);
    window.setTimeout(function() {
        gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, function(authResult) {
            gapi.client.load('plus', 'v1', function() {
                var request = gapi.client.plus.people.get({
                    'userId': 'me'
                });
                request.execute(function(resp) {
                    if (resp != "" && resp.result != "") {
                        var user = {
                            email: resp.emails[0].value,
                            description: 'Tên : ' + resp.displayName + ' , giới tính : ' + resp.gender,
                        };

                        ajax({
                            service: 'cpservice/auth/signin.json',
                            data: user,
                            type: "post",
                            contentType: 'json',
                            done: function(resp) {
                                if (resp.success) {
                                    location.href = baseUrl + 'cp/index.html';
                                } else {
                                    popup.msg(resp.message);
                                }
                            }
                        });
                    }
                });
            });
        });
    }, 1);
};